﻿using System;
using System.Windows.Forms;

//class that represents a team.  Can be queried to get the team's name, scores, and whether or not they have been selected by the user.
public class Team
{
    //variables that represent the team
    string teamname = "";
    Guid teamID;
    //array of scores for the games
    /*
      Score represent the results of a game or its status
      Valid values for scores are as follows:
      2 - Win
      1 - Tie
      0 - Loss
     -1 - Bye Week
     -2 - Future game (No final score for game yet)
    */ 
    int[] scores = new int[17];
    bool selected = false;
    //value representing which column the team will be assigned to in the UI
    //valid values are 0, 1, 2
    int column;
    //not currently used
    //String teamDescription ="";
	public Team()
	{
        teamname = "";
        column = 1;
        setScore(0, -1);
        setScore(1, -1);
        setScore(2, -1);
        setScore(3, -1);
        setScore(4, -1);
        setScore(5, -1);
        setScore(6, -1);
        setScore(7, -1);
        setScore(8, -1);
        setScore(9, -1);
        setScore(10, -1);
        setScore(11, -1);
        setScore(12, -1);
        setScore(13, -1);
        setScore(14, -1);
        setScore(15, -1);
        setScore(16, -1);
        //column;
	}
    public Team(string TeamName, int TeamColumn, int score1, int score2, int score3, int score4, int score5, int score6, int score7, int score8, int score9, int score10, int score11, int score12, int score13, int score14, int score15, int score16, int score17)
    {
        teamname = TeamName;
        column = TeamColumn;
        setScore(0, score1);
        setScore(1, score2);
        setScore(2, score3);
        setScore(3, score4);
        setScore(4, score5);
        setScore(5, score6);
        setScore(6, score7);
        setScore(7, score8);
        setScore(8, score9);
        setScore(9, score10);
        setScore(10, score11);
        setScore(11, score12);
        setScore(12, score13);
        setScore(13, score14);
        setScore(14, score15);
        setScore(15, score16);
        setScore(16, score17);
    }

    public int teamColumn
    {
        get
        {
            return column;
        }
        set
        {
            column = value;
        }
    }

    public Guid teamId
    {
        get
        {
            return teamID;
        }
        set
        {
            teamID = value;
        }
    }

    public string teamName
    {
        get
        {
            return teamname;
        }

        set
        {
            teamname = value;
        }
    }

    public bool isSelected
    {
        get
        {
            return selected;
        }
        set
        {
            selected = value;
        }
    }

    public int getScore(int weeknumber)
    {
        //bounds checking; since the size of the array is fixed, values used in the bounds checking are fixed as well
        //if weeknumber is not a valid array index number, return a value to be used for error checking
        if (weeknumber > 17)
        {
            MessageBox.Show("Error: invalid value in parameter weeknumber: " + weeknumber + " in Team.getScore", "Invalid value in parameter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return -3;
        }
        if (weeknumber < 0)
        {
            MessageBox.Show("Error: invalid value in parameter weeknumber: " + weeknumber + " in Team.getScore", "Invalid value in parameter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return -3;
        }
        //if it's a valid index number return the value at index
        return scores[weeknumber];
    }
    //sets the scores into the scores array; valid values for weeknumber are: 0-16; valid values for scores are -2 - 2
    public void setScore(int weeknumber, int score)
    {
        //bounds checking; since the size of the array is fixed, values used in the bounds checking are fixed as well
        //if weeknumber is not a valid array index number, displays a messagebox that describes the issue
        if (weeknumber > 17)
        {
            MessageBox.Show("Error: invalid value in parameter weeknumber: " + weeknumber + " in Team.setScore", "Invalid value in parameter", MessageBoxButtons.OK, MessageBoxIcon.Error);
            
        }
        if (weeknumber < 0)
        {
            MessageBox.Show("Error: invalid value in parameter weeknumber: " + weeknumber + " in Team.setScore", "Invalid value in parameter", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        //more parameter checking
        switch (score)
        {
            case -2:
                {
                    scores[weeknumber] = score;
                    break;
                }
            case -1:
                {
                    scores[weeknumber] = score;
                    break;
                }
            case 0:
                {
                    scores[weeknumber] = score;
                    break;
                }
            case 1:
                {
                    scores[weeknumber] = score;
                    break;
                }
            case 2:
                {
                    scores[weeknumber] = score;
                    break;
                }
            default:
                {
                    MessageBox.Show("Error: invalid value in parameter score: " + score + " in Team.setScore", "Invalid value in parameter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
        }
        
    }
}
